<%@page import="com.spmanage.util.HttpUtil"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="com.spmanage.util.BillingUtil"%><%@page import="com.spmanage.util.DbOperation"%>
<%@page import="com.spmanage.util.SqlUtil"%><%@page import="com.spmanage.util.WebAction"%>
<%@page import="com.spmanage.util.StringUtil"%><%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%><%
	WebAction webAction = new WebAction(request,response);
    
	System.out.println("北纬-IVR挂断参数："+request.getQueryString());
    
    String mobile = webAction.getParameterString("mobile");		//用户手机号
    String callno = webAction.getParameterString("called");		//拨打号码
    String calltime = webAction.getParameterString("btime");   	//拨打时间:20091107004646,需转换成2009-11-07 00:46:46
    String halttime = webAction.getParameterString("etime");	    //挂断时间:20091107004843
    String feeseconds = webAction.getParameterString("time");	//拨打时长,时长(分钟)，比如183秒，时长就是4
    
    if(mobile==null||callno==null){
    	response.getWriter().write("err");
    }else{
    	response.getWriter().write("1");
	    String carrier = "";	 //运营商
	    int fee = 0;			 //资费
	    int shichang = 0;        //时长，秒
	    
	    //时长，截取最后4位，算出多少秒
	    shichang = Integer.parseInt(halttime.substring(10,14))-Integer.parseInt(calltime.substring(10,14));
	    
	    //参数修改格式
	    if(calltime!=null){
	    	calltime = calltime.substring(0,4)+"-"+calltime.substring(4,6)+"-"+calltime.substring(6,8)+" "+calltime.substring(8,10)+":"+calltime.substring(10,12)+":"+calltime.substring(12,14);
	    }
	    if(halttime!=null){
	    	halttime = halttime.substring(0,4)+"-"+halttime.substring(4,6)+"-"+halttime.substring(6,8)+" "+halttime.substring(8,10)+":"+halttime.substring(10,12)+":"+halttime.substring(12,14);
	    }
	    //资费，按分钟数来计算，一分钟100分
	    if(feeseconds!=null){
	    	fee = Integer.parseInt(feeseconds+"00");
	    }
	    //最后赋值给feeseconds,以便后面的操作，这个精确到秒的
	    feeseconds = String.valueOf(shichang);
	    
	    System.out.println("北纬-IVR挂断参数资费："+fee+"；开始时间："+calltime+";结束时间："+halttime);
	    
	    StringBuilder getChannelIdSql = new StringBuilder("select cpid from adminspcp where spcommand = '");
	    getChannelIdSql.append(callno);
	    getChannelIdSql.append("'");
	    int channel =SqlUtil.getIntResult(getChannelIdSql.toString(),5) ;
	    int ischeck = BillingUtil.getIvrCheckCall(channel);
	    
	    int provinceId = BillingUtil.getProvinceId(mobile);
	    
	    String spId = "153";//spid：85,后期还能会变成动态的
	   
	    //------------------------------------------------------
		//合作方url
		String url="";
		if(callno.equals("1259057565")){
			//channel="10063";
			url="http://116.213.132.29/logwrite/spxtsd_ivr.jsp";
			url=url+"?ani="+mobile+"&dnis="+callno+"&stime="+URLEncoder.encode(calltime,"UTF-8")+"&etime="+URLEncoder.encode(halttime,"UTF-8")+"&seclen="+feeseconds+"&fee="+fee;;
			System.out.println("高谷-影乐通-IVR同步:"+url);
			HttpUtil.getHtmlSource(url,"UTF-8");
		}
	
		//-------------------------------------------------------
		//保存到ivr天表
	    StringBuilder conditionSql = new StringBuilder();
	    conditionSql.append("'");
	    conditionSql.append(spId);
	    conditionSql.append("','");
	    conditionSql.append(channel);//渠道号,后期还能会变成动态的
	    conditionSql.append("','");
	    conditionSql.append(provinceId);//省份ID
	    conditionSql.append("','");
	    conditionSql.append(mobile);//手机号
	    conditionSql.append("','");
	    conditionSql.append(callno);
	    conditionSql.append("','");
	    conditionSql.append(fee);
	    conditionSql.append("','");
	    conditionSql.append(carrier);
	    conditionSql.append("','");
	    conditionSql.append(calltime);
	    conditionSql.append("','");
	    conditionSql.append(halttime);
	    conditionSql.append("','");
	    conditionSql.append(feeseconds);
	    conditionSql.append("','");
	    conditionSql.append(ischeck);
	    conditionSql.append("',");
	    conditionSql.append("getDate()");
	    System.out.println(conditionSql.toString());
	    SqlUtil.executeUpdate("insert into  "+BillingUtil.getIvrHaltDay()+"(areaid,channel,province,mobile,callno,fee,carrier,calltime,halttime,feeseconds,ischeck,createdtime) values("+conditionSql.toString()+")",DbOperation.DB_STAT);
    }

%>
